const getDateKey = () => {
  let today = new Date()
  let year = today.getFullYear()
  let month = today.getMonth() + 1
  let date = today.getDate()
  return year + '-' + month + '-' + date
}

/** 每日免费拦截 */
const freeTimesIntercept = () => {
  return new Promise((resolve, reject) => {
    let key = getDateKey()
    const markData = uni.getStorageSync(key);
    if (markData && markData >= 2) {
      uni.showModal({
        title: '提示',
        content: '每天免费2次机会已用完，看一段几秒的广告即可免费去水印',
        success: function(res) {
          if (res.confirm) {
            vk.myfn.HmUtils.AdVideo.videoAdShow()
            .then((res) => {
              res && resolve();
              !res && reject();
            });
          } else if (res.cancel) {
            console.log('用户点击取消');
            reject()
          }
        }
      });
    } else {
      let times = markData || 0;
      uni.setStorageSync(key, times + 1);
      resolve();
    }
  });
}

export default {
  freeTimesIntercept,
  getDateKey
}